// src/store/service/auth.ts
// import { LoginFormState } from "@pages/login";
import apiService from "@service/index";
import { saveCredentials } from "@slice/credentials";

const authApiService = apiService.injectEndpoints({
  endpoints: (builder:any) => ({
    // 用户登录注册
    login: builder.mutation({
      query: (body:any) => ({
        url: "/authorizations",
        method: "post",
        body,
      }),
      onQueryStarted: async (arg:any, api:any) => {
        // 捕获错误
        try {
          // 等待请求完成
          const response = await api.queryFulfilled;
          // 将用户凭证存储到状态切片
          api.dispatch(saveCredentials(response.data.data));
        } catch (error) { }
      },
      endpoints: (builder:any) => ({
        // 发送手机验证码
        sendMsgCode: builder.query({
          query: (mobile:any) => ({ url: `/sms/codes/${mobile}` }),
        }),
      }),
    }),
  }),
});


// export const { useLazySendMsgCodeQuery } = authApiService;
export const { useLoginMutation } = authApiService;